package com.huawei.hwid.api.common;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.RemoteException;
import com.huawei.cloudservice.CloudAccountManager;
import com.huawei.cloudservice.IntentResultHandler;
import com.huawei.cloudservice.c;
import com.huawei.cloudservice.c.a;
import com.huawei.hwid.core.constants.HwAccountConstants;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.helper.handler.ErrorStatus;

public class j extends b {
    private IntentResultHandler d;
    private String e;
    private String f;
    private String g;
    private Bundle h;

    public j(Context context, String str, String str2, Bundle bundle, IntentResultHandler intentResultHandler) {
        super(context);
        this.d = intentResultHandler;
        this.e = str;
        this.f = context.getPackageName();
        this.g = str2;
        this.h = bundle;
    }

    void b() {
        a a = a.a(this.c);
        if (a != null) {
            try {
                a.a().a(this.e, this.f, this.g, a(this.d));
            } catch (RemoteException e) {
                e.b("RemoteAccessAuthorizeIntentTask", "remote exception", true);
            }
        }
    }

    void a(ErrorStatus errorStatus) {
        if (errorStatus == null) {
            errorStatus = new ErrorStatus(39, "timeout. retry again");
        }
        this.d.onError(errorStatus);
    }

    private c a(final IntentResultHandler intentResultHandler) {
        return new a(this) {
            final /* synthetic */ j b;

            public void a(int i, Bundle bundle) throws RemoteException {
            }

            public void a(int i, Intent intent) throws RemoteException {
                if (this.b.b.get()) {
                    e.b("RemoteAccessAuthorizeIntentTask", "has cancelled by timeout, return directly", true);
                    return;
                }
                if (i == 3) {
                    if (!(intent == null || this.b.h == null || !HwAccountConstants.FORGOT_PWD_INTENT.equals(this.b.e))) {
                        intent.putExtra(CloudAccountManager.KEY_LOGIN_CHANNEL, this.b.h.getInt(CloudAccountManager.KEY_LOGIN_CHANNEL));
                        intent.putExtra(CloudAccountManager.KEY_REQCLIENTTYPE, this.b.h.getInt(CloudAccountManager.KEY_REQCLIENTTYPE));
                        intent.putExtra("isOOBE", this.b.h.getBoolean("isOOBE"));
                    }
                    intentResultHandler.onFinish(intent);
                } else if (i == 0) {
                    intentResultHandler.onError(new ErrorStatus(31, "Account hasnot login"));
                } else if (i == 1) {
                    intentResultHandler.onError(new ErrorStatus(29, "Signature invalid"));
                } else if (i == 5) {
                    intentResultHandler.onError(new ErrorStatus(12, "userId invalid"));
                } else {
                    intentResultHandler.onError(new ErrorStatus(12, "params error"));
                }
                this.b.a();
            }

            public void a(int i) throws RemoteException {
            }

            public void b(int i, Bundle bundle) throws RemoteException {
            }
        };
    }
}
